<template>
	<view class="index" :style="{backgroundImage: 'url('+imgurl+')'}">
		<view class="content">
			<view class="serchBox">
				<view class="serchButton" @click="goSearch">
					<image src="../../static/images/search_icon.png"></image> 搜索你想要的商品
				</view>
				
			</view>
			<view class="swiperBox">
				<swiper class="swiperBanner" indicator-active-color="#E8271B" :indicator-dots="true" :autoplay="true" :interval="3000"
				 :duration="1000" :circular="true" >
					<swiper-item v-if="bannerList"  v-for="(item,index) in bannerList" :key='index' @tap="goSeckill">
						<view class="swiper-item">
							<image :src="item.img" lazy-load="true" mode="scaleToFill"></image>
						</view>
					</swiper-item>
					<swiper-item v-else>
						<view class="swiper-item">
							<!-- <image src="../../static/images/image_1.png" mode="scaleToFill"></image> -->
						</view>
					</swiper-item>
				</swiper>
			</view>
			<view class="quickNav">
				<view class="uni-list quickNavLists">
					<view class="uni-list-cell quickNavList" v-for="(item,index) in 10" :key="index" @tap="goList(item.categoryId,item.iconName)" >
						<image src="/static/images/denglu.png" ></image>
						<view>测试</view>
					</view>
				</view>
			</view>
			
			<!-- <view class="adBox">
				<view style="height: 350upx;" @tap="goSeckill">
					<view class="title" >
						限时秒杀
					</view>
					<view class="countDown" v-if="isHasMiaosha">
						<view class="leftHouer">
							<image src="../../static/images/sale_icon.png" ></image> <text>{{miaosha.activityName}}</text>
						</view>
						<view class="rightSec">
							{{times}}
						</view>
					</view>
					<view class="commoditys">
						<view class="commodity" style="margin-left: 20upx;">
								<image v-if="miaosha.activityName != null" :src="miaosha.list[0].mainImg" mode="scaleToFill"></image>
							<image v-else src="../../static/images/xianshi.png" mode="scaleToFill"></image>
							
							<view class="price">
								￥<text>{{miaosha.list[0].activityPrice || 0}}</text>
							</view>
							<view class="oldprice">
								￥{{miaosha.list[0].price || 0}}
							</view>
						</view>
						<view class="commodity" style="margin-right: 50upx;">
								<image v-if="miaosha.activityName != null" :src="miaosha.list[1].mainImg" mode="scaleToFill"></image>
								<image v-else src="../../static/images/xianshi.png" mode="scaleToFill"></image>
							<view class="price">
								￥<text>{{miaosha.list[1].activityPrice || 0}}</text>
							</view>
							<view class="oldprice">
								￥{{miaosha.list[1].price || 0}}
							</view>
						</view>
						
					</view>
				</view>
				<view style="height: 350upx;" @tap="goList(2,'大牌抢购')">
					<view class="title">
						大牌抢购
					</view>
					<view style="color: #E752F5; font-size: 24upx;font-weight: 500;">购大牌好物</view>
					<view class="bigName">
						<image v-for="(item,index) in majorList" :key="index" :src="item.pic.split(',')[0]" mode="scaleToFill"></image>
					</view>
				</view>
				<view style="height: 256upx;" class="last"  @tap="goList(1,'必买清单')">
					<view class="title">
						必买清单
					</view>
					<view style="color: #32B51D; font-size: 24upx;font-weight: 500;">剁手必看 长草神器</view>
					<view class="mustBuy">
						<image v-for="(item,index) in mustList" :key="index" :src="item.pic.split(',')[0]" lazy-load="true" mode="scaleToFill"></image>
					</view>
				</view>
				<view style="height: 256upx;" class="last" @tap="goList(3,'天天特价')">
					<view class="title">
						天天特价
					</view>
					<view style="color: #F39606; font-size: 24upx;font-weight: 500;">低价抢购</view>
					<view class="everySpecial">
						<image v-for="(item,index) in specialList" :key="index" :src="item.pic.split(',')[0]" lazy-load="true" mode="scaleToFill"></image>
					</view>
				
				</view>
				
			</view> -->
		
			<view class="foryourSelect">
				<view class="title">
					<image src="../../static/images/circle_1.png" lazy-load="true" mode="scaleToFill"></image>
					<text>为你精选</text>
					<image src="../../static/images/circle_2.png" lazy-load="true" mode="scaleToFill"></image>
				</view>
				<view >
					
					<view class="uni-list selectLists">
						<view class="uni-list-cell selectList" v-for="(item,index) in selectList" :key="index" @tap="goDetails(item)">
							<view class="imgbox">
								<image :src="item.pic.split(',')[0]" lazy-load="true" mode="scaleToFill"></image>
							</view>
							<view class="desction">
								{{item.name}}
							</view>
							<view class="priceBox">
								<view class="price">
									￥{{item.price}}
								</view>
								<view class="salesNum">
									总销量{{item.sale}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view v-if="showMask" class="mask" @touchmove.stop.prevent="moveHandle">
				<!-- <canvas  id="test-canvas" canvas-id="test-canvas"></canvas> -->
				<view style="position: relative;width: 80%;">
					
				<image class="adImg" :src="adObj.img" mode="widthFix" @tap.stop="goAd"></image>
				<!-- <view id="animation" ref="animation">
					
				</view> -->
				<view class="imgs">
					<image @tap.stop="closeMask" src="../../static/images/xx.png" mode="widthFix"></image>
				</view>
				</view>
		</view>
	
	</view>
</template>

<script>
	// import lottie from 'lottie-miniapp'
	// const canvasContext = wx.createCanvasContext('test-canvas');
	
	export default {
		data() {
			return {
				bannerList:[{img:"https://img-shop.qmimg.cn/s23107/2020/04/27/4ebdb582a5185358c4.jpg?imageView2/2/w/600/h/600"}],
				imgurl: "../../static/images/bg_red.png",
				quickNav: [],
				miaosha:{},
				times:"",
				isHasMiaosha:false,
				defaultImg:'this.src='+require('../../static/images/xianshi.png'),
				majorList:[],
				mustList:[],
				specialList:[],
				showMask:false,
				selectList:[],
				pageNum:1,
				loadStatusText: '加载中...',
				adObj:{}
			}
		},
		onReady(){
			// if(this.$store.state.isShowMask == false){
			// 	this.showMask = true;
			// 	uni.hideTabBar()
			// 	this.$store.commit('changeIsShowMask',true)
			// }else{
			// 	this.showMask = false
			// 	uni.showTabBar()
			// }
		},
		onLoad() {
			// this.getBannerData()
			// this.getquickNav()
			// this.getmustbuyData()
			// this.getAdInfo()
			// this.getSelected()
		},
		onShow() {
			// this.getANproduct()
		},
		onReachBottom() {
			// this.getSelected()
		},
		onPullDownRefresh(){
			// this.pageNum = 1
			// this.selectList = []
			// Promise.all([this.getBannerData(),this.getquickNav(),this.getANproduct(),this.getSelected()]).then(res=>{
			// 	uni.stopPullDownRefresh();
			// })
		},
		methods: {
			getBannerData(){
				let data = {
					"pageId": "1",
					fitType:'2'
				}
				this.$http.post(this.$http.baseUrl+'/api/v1.0/admin/banner/AllBanner',data,(res)=>{
					this.bannerList = res.data.data
				})
			},
			getquickNav(){
				this.$http.post(this.$http.baseUrl+'/api/v1.0/admin/icon/AllIcon',{pageId:1},(res)=>{
					this.quickNav = res.data.data
				})
				
			},
			//秒杀两个商品
			getANproduct(){
				let _this = this;
				if(this.times != ""){
					clearInterval(this.timer)
				}
				let data = {
					pageId:"123",
					userId: "",
				}
				this.$http.post(this.$http.baseUrl+'/api/v1.0/activity/findANProduct',data,res=>{
					this.miaosha = res.data.data
					if(res.data.data.activityName != null){
						let time = Math.floor(res.data.data.surplusTime / 1000)
						// let time = 10
						console.log(Math.floor(res.data.data.surplusTime / 1000))
						var that = this;
						that.times = that.transform(time)
						
						this.timer = setInterval(function(){
							time--
							that.times = that.transform(time)
							if(time == 0){
								clearInterval(_this.timer)
								_this.getANproduct()
								return
							}
						},1000)
						
						this.isHasMiaosha = true;
					}else{
						this.isHasMiaosha = false;
					}
				})
			},
			getmustbuyData(){
				let data = {
					pageId:"123",
					userId: "string",
				}
				this.$http.post(this.$http.baseUrl+'/api/v1.0/app/product/findIndexActivityProduct',data,res=>{
					// console.log(res.data)
					this.majorList = res.data.data.mustList
					this.mustList = res.data.data.majorList
					this.specialList = res.data.data.specialList
				})
				
			},
			transform(secs){
				if(secs){
				  var second  = parseFloat((secs % 60).toFixed(1)); 
				  var minute = Math.floor(secs/ 60) % 60;
				  var hour = Math.floor(secs / 3600) % 24;
				  second = second<10? '0'+second : second;
				  minute = minute<10? '0'+minute : minute;
				  hour = hour<10? '0'+hour : hour;
				  return  hour +":"+ minute+":"+ second
			    }else{
			      return secs
			    }
			},
			goSearch(){
				uni.navigateTo({
					url: '../search/search',
				});
			},
			goSeckill(){
				uni.navigateTo({
					url: '../seckill/seckill',
				});
			},
			moveHandle(e){
				 e.preventDefault(); 
				 return;
			},
			//弹窗广告
			getAdInfo(){
				let data = {
					"advertisingPage": "X1",
					"fitType": "2",
					"status": 1
				}
				this.$http.post(this.$http.baseUrl + '/api/v1.0/route/Advertising/queryAdvertisingRouteRequest',data,res=>{
					console.log(res.data.data)
					this.adObj = res.data.data[0]
				})
			},
			closeMask() {
				this.showMask = false;
				uni.showTabBar()
			},
			getSelected(){
				let data = {
					  "pageNum": this.pageNum,
					  "pageSize": 10,
					  "recommandStatus": 1,
				}
				var _this = this
				this.$http.post(this.$http.baseUrl + '/api/v1.0/app/product/ProductTopSell',data,res=>{
					this.pageNum++
					if(res.data.data.length == 0){
						_this.loadStatusText = "已加载全部"
						return false;
					}else{
						_this.loadStatusText = "加载成功"
						if(_this.selectList.length == 0){
							_this.selectList = res.data.data;
						}else{
							_this.selectList = _this.selectList.concat(res.data.data);
						}
					}
				})
			},
			goDetails(e){
				uni.navigateTo({
					url:'/pages/details/details?id=' + e.id
				})
			},
			goAd(){
				let _this = this;
				uni.navigateTo({
					url:'../agreement/agreement?url=' + JSON.parse(_this.adObj.activityPath).html5 + '&title=' + _this.adObj.activityName
				})
				// this.closeMask()
				
			},
			goList(num,name){
				uni.navigateTo({
					url:"/pages/listComponents/listComponents?titleId=" + num + '&name=' + name
				})
			},
		}
	}
</script>

<style lang="scss">
	.index {
		background-repeat: no-repeat;
		background-size: 100%;
		background-color: #f2f2f2f2;
		.serchBox {
			padding-top: 54upx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			position: relative;
			.msgIcon {
				width: 48upx;
				height: 48upx;
				line-height: 64upx;
			}
			.point {
				width: 20upx;
				height: 20upx;
				border-radius: 50%;
				background-color: #FFD200;
				position: absolute;
				right: 0;
				top: 35upx;
			}
		}
		.serchButton {
			width: 694upx;
			background-color: #fff;
			border-radius: 32upx;
			height: 64upx;
			line-height: 64upx;
			font-size: 28upx;
			color: #BFBFBF;
			display: flex;
			align-items: center;
			justify-content: flex-start;
			image {
					width: 40upx;
					height: 40upx;
					margin-left: 38upx;
				}
		}
		.swiperBox {
			margin-top: 40upx;
			border-top-left-radius: 20upx;
			border-top-right-radius: 20upx;
			overflow: hidden;
		}
		.swiperBanner {
			height: 280upx;
		}
		.swiper-item {
			height: 100%;
			width: 100%;
			
			image {
				height: 100%;
				width: 100%;
			}
		}
		.quickNav .quickNavLists{
			display: flex;
			justify-content: space-between;
			flex-direction: row;
			flex-wrap: wrap;
			margin-top: 40upx;
			.quickNavList{
				width: 84upx;
				height: 127upx;
				text-align: center;
				margin-right: 63upx;
				margin-bottom: 20upx;
				image{
					width: 84upx;
					height: 84upx;
				}
				view{
					font-size: 20upx;
					color: #4d4d4d;
				}
				
			}
			.quickNavList:nth-child(5n){
				margin-right: 0;
			}
			
			
		}
		.adBox{
			background-color: #fff;
			border-radius: 20upx;
			height: 607upx;
			width: 694upx;
			margin-top: 50upx;
			>view{
				float: left;
				width: 50%;
				box-sizing: border-box;
				border-right: 1upx solid #F2F2F2;
				border-bottom: 1upx solid #F2F2F2;
				padding-left: 30upx;
				padding-top: 30upx;
				.title{
					font-size: 40upx;
					font-weight: bold;
					color: #333;
					// margin-top: -10upx;
				}
				.countDown{
					display: flex;
					justify-content: space-between;
					.leftHouer {
						display: inline-block;
						line-height: 38upx;
						display: flex;
						align-items: center;
						image{
							width: 38upx;
							height: 38upx;
							margin-right: 5upx;
						}
						text{
							font-size: 28upx;
							color: #F63810;
							font-weight: bold;				
						}
					}
				.rightSec{
					margin-right: 14upx;
					width: 150upx;
					height: 38upx;
					text-align: center;
					background-color: #f63810;
					color: #fff;
					font-size: 26upx;
					lighting-color: 38upx;
					border-radius: 19upx;
				}
				}
				.commoditys{
					display: flex;
					justify-content: space-between;
					margin-top: 20upx;
					.commodity{
						image{
							width: 100upx;
							height: 100upx;
						}
						.price{
							color: #F63810;
							font-size: 24upx;
							text-align: center;
							text{
								font-size: 32upx;
							}
							
						}
						.oldprice{
							color: #B3B3B3;
							font-size: 24upx;
							text-align: center;
							text-decoration:line-through;
						}
					}
				}
				.bigName{
					image{
						width: 126upx;
						height: 180upx;
						margin-right: 35upx;
						&:nth-child(2){
							margin-right: 0;
						}
					}
				}
				.mustBuy{
					image{
						width: 132upx;
						height: 90upx;
						margin-right: 22upx;
						&:nth-child(2){
							margin-right: 0;
						}
					}
					
				}
				.everySpecial{
					image{
						width: 126.4upx;
						height: 102upx;
						margin-right: 32.2upx;
						&:nth-child(2){
							margin-right: 0;
						}
					}
				}
				&.last{
					border-bottom: none;
				}
				
			}
			
		}
		.foryourSelect{
			margin-top: 50upx;
			// padding-bottom: 120upx;
			.title{
				display: flex;
				align-items: center;
				text-align: center;
				justify-content: center;
				image{
					width: 78upx;
					height: 6upx;
				}
				text{
					font-size: 28upx;
					color: #4d4d4d;
					font-weight: 500;
					margin: 0 10upx;
				}
			}
			.selectLists{
				margin-top: 50upx;
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;
				.selectList{
					border-radius: 20upx;
					background-color: #fff;
					overflow: hidden;
					width: 334upx;
					height: 530upx;
					margin-right: 25.7upx;
					margin-bottom: 26upx;
					&:nth-child(2n){
						margin-right: 0;
					}
					image{
						width: 334.3upx;
						height: 333upx;					
					}
					.desction{
						width: 297upx;
						margin: 24upx auto;
						color: #333;
						font-weight: 500;
						font-size: 28upx;
						display: -webkit-box;
						overflow: hidden; 
						white-space: normal!important;
						text-overflow: ellipsis;
						word-wrap: break-word; 
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
						
					}
					.priceBox{
						display: flex;
						justify-content: space-between;
						width: 297upx;
						margin: 0 auto;
						.price{
						color: #F63810;
						font-size: 24upx;
							text{
								font-size: 32upx;
								font-weight: bold;
							}
						}
						.salesNum{
							color: #4d4d4d;
							font-size: 24upx;
						}
					}
					
				}
			}
			.loadStatusText{
				font-size: 24upx;
				text-align: center;
				color: #999999;
				height: 100upx;
				line-height: 100upx;
			}
		}
		.mask {
			position: fixed;
			top: 0;
			left: 0;
			z-index: 999;
			width: 100%;
			height: 100vh;
			background: rgba(0, 0, 0, 0.4);
			overflow: hidden;
			display: flex;
			align-items: center;
			justify-content: center;
			.adImg{
				width: 100%;
			}
			.imgs{
				width: 78upx;
				height: 78upx;
				position: absolute;
				top: 0upx;
				right: 0upx;
				image {
					width: 78upx;
					height: 78upx;
				}
			}
			
		}
	}

	.content {
		width: 694upx;
		margin: 0 auto;
	}
 


</style>
